: 1 String str1= "AB" ; 2 String str2= "AB" ; 3 String str6=STR2; 4 System.out.println (STR1==STR6); // true 5 System.out.println (STR2==STR6); // true 6 System.out.println (str1.equals (STR6)); // true 7 System.out.println (str2.equals (STR6)); // true This assigns the value of the STR2 to STR6 because the AB string already exists in the constant pool, so str1, str2, and STR6 share the same object, and = = also returns true with EqualsExperiment Four:1 New String ("abc");2 string
1. The role of the final keyword 1.1, Final decorated class: Cannot be inherited by another class; 1.2, final Modified method: cannot be overridden by a quilt class 1.3, final modified variables: In two cases, reference variables, basic type variables, as follows: final decorated reference variable: once assigned, it cannot be re-assigned Final // reference variable s = "1"; /** Error: The final local variable s cannot be assigned. It must is blank and not using a compound assi
Objective:
In peacetime we use the string is generally used to get directly, very little in-depth to think about this knowledge , leading to others in the examination of our time, will ask the string str = new String ("123"); This line of code executes several objects, String str1= str + new String ("456"), where in this line of code is the str1 stored in memory, heap or string constant area (method area)? Will put our questions speechless , haha haha, in fact, is not the level of problems, is t
Python learns the sequence of data types, and python Data Types
I. Sequence (this article uses python3.5)######################################## ##################### List and tuples are all Sequences# Features:#1. You can obtain specific elements through indexes.#2. You can obtain a small sequence through the slice operation.# Basic operationsStr = "abc ";Str1 = "efg ";Print (len (str); # obtain the sequence lengthPrint (str + str1); # concatenate SequencesPrint (str * 5); # repeat the sequenc
How can variable initialization be more efficient? Check the disassembly code of the VC and GCC compilers to see the efficiency difference of initialization of different methods. The CL version of Windows compiler is Microsoft (r) 32-bit C/C ++ Optimizing Compiler version 12.00.8168 for 80x86, and GCC version is 4.5.3.
Source code:
void funA(){char *str1="helloworld";}void funB(){char str2[]="helloworld";}void funC(){char str3[11]="helloworld";}void funD(){char
What does copy mean?
1) For non-container objects such as NSString and NSNumber
NSString * str1 = @ "abc ";NSString * str2 = [str1 copy]; // The address is the same as that of Str1.NSString * str3 = [str1 mutableCopy]; // The address is different from str1. Although it is a deep copy, the content of str3 cannot be modified (the syntax is not passed)NSMutableString * str4 = [str1 copy]; // The address is the same as that of Str. Modifying
form a word
\d
Digital
\d
Non-digital
\b
The boundary of a word
\b
is not the boundary of a word
\ t
Horizontal tab
\v
Vertical tab
\f
Page break
\ r
Carriage return character
\ n
Line break
\CA: \cz
controls, such as \CM, match a ctrl+m
\x0000: \XFFFF
Hexadecimal U
"; which is different from what we usually do? Generally, when "+" is used to connect two strings, a new character object is generated. Let's take a look at the example below to understand:Java code
String str1 = "AAA ";
String str2 = "BBB ";
String str3 = "aaabbb ";
String str4 = "AAA" + "BBB"; // No New String object will be generated
System. Out. println (str3 = str4); // true
. This line of code compiles with string str= "aaabbb"; Is it the same as we usually do? Generally using "+" to concatenate two strings will result in another new character object. Let's take a look at the example below to understand:Java code
String str1 = "AAA";
String str2 = "BBB";
String STR3 = "aaabbb";
String STR4 = "AAA" + "BBB"; //does not produce a new string object
System.out.println (STR3 = =
has no attributes and method 2. the call basic type will generate a temporary packaging object. After the call is complete, the packaging object will be consumed. If you want to obtain the pseudo attribute of the basic type, undefined will be returned. */Var str4 = 'alien'; console.info ("str4.length:" + str4.length); console.info ("
when two string objects have the same value, they reference only the same copy in the constant pool, which can save significant memory space when the same string repeats itself.The following code str1, str2, STR4 refer to the same address, but STR3 re-opens up a memory space, although STR3 occupies the heap space alone, but it points to the same entity as the str1. The code is shown in Listing 1 below.Listing 1. Sample codepublic class Stringdemo {pu
PrintRe.sub ("L",""A
Java using the String method replacePython can also use the Replace method. Or use the RE module.6. Judging string equality
Java
Python
1 Public classTest {2 Public Static voidMain (String args[]) {3String str1 = "Hello,world";4String str2 = "Hello,world";5String STR3 =NewString ("Hello,world");6String STR4 =STR3;7System.out.println ("str1 equals str2:" +str1.equals (str2));8Syste
line 17th is the same. Six, typedef and # define1. Let's see what the difference is between the following two sections (note the 1th line of code for each paragraph)* 1th ParagraphChar *String; int Main (intconstChar * argv[]) { "This isa string! " ; return 0 ;}* 2nd paragraph#define String char *int main (intconstChar * argv[]) { "This is A string! " ; return 0 ;}The above two code is only the 1th line of code is different, the effect is the same: defined a string "This is a stri
common method of string. Capitalize () First letter capital ★★☆☆☆>>> str4 = 'hellokitty'>>> str4.capitalize()'Hellokitty'Center () strings are populated before and after the custom character ★★☆☆☆>>> str4 = 'hellokitty'>>> str4.center(20, '*')'*****hellokitty*****'Upper () English full capitalization; lower () English
argc, const char * argv[]) {4 String str = "This is a string!"; 5 return 0;6}* 2nd paragraph1 #define String char * * 3 int main (int argc, const char * argv[]) {4 string str = "This is a string!"; 5 return 0;6}The above two code is only the 1th line of code is different, the effect is the same: defined a string "This is a string!".But the way they are implemented is not the same:
The 1th code is a typedef to char * defines the alias string
The 2nd code uses char *
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.